package com.hp.tiger.chapter3;

import java.util.concurrent.TimeUnit;

/**
 * @author XavierDong
 **/
public class VolatileTest2 {


    /**
     * 内存可见性，顺序性
     */
    private static int INT_VALUE = 0;
    private static final int MAX_LIMIT = 50;

    public static void main(String[] args) {

        new Thread(() -> {
            while (INT_VALUE < MAX_LIMIT) {
                System.out.println("T1 -> " + (++INT_VALUE));
                try {
                    TimeUnit.MILLISECONDS.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "ADDER-1").start();


        new Thread(() -> {
            while (INT_VALUE < MAX_LIMIT) {
                System.out.println("T2 -> " + (++INT_VALUE));
                try {
                    TimeUnit.MILLISECONDS.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "ADDER-2").start();
    }
}
